package web

import (
	"homeserver/family"
	"encoding/json"
)


type familyTransferCell struct {
	MemId 	string			`json:"mem"`
	Data 	interface{}		`json:"data"`
}

type familyNotifyOjb struct {}

//
// 处理通知消息
//
func ( *familyNotifyOjb) HandleNotify(buffer []byte) (err error)  {
	err = nil

	var notify familyTransferCell
	err = json.Unmarshal(buffer, &notify)
	if err != nil {
		return err
	}

	data, err := json.Marshal(notify.Data)
	if err != nil {
		return
	}

	postNotify(notify.MemId, data)

	return
}

//
// 想家庭中心订阅通知消息
//
func subscribeFamilyNotify() error {
	f := &familyNotifyOjb{}
	family.SubscribeNotify(f)
	return nil
}

// 想家庭中心发送消息
func sendRequest(memId string, data []byte) (err error) {
	var i interface{}
	err = json.Unmarshal(data, &i)
	if err != nil {
		return
	}

	request := familyTransferCell{
		MemId: memId,
		Data: i,
	}

	buf, _ := json.Marshal(request)
	family.RequestOperate(buf)
	return nil
}



